<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机身串" prop="imeiCode">
        <el-input
          v-model="queryParams.imeiCode"
          placeholder="请输入机身串"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="clientUserList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column
        label="手机号"
        width="120px"
        align="center"
        prop="phone"
      />
      <el-table-column label="机身串" align="center" prop="imeiCode" />
      <el-table-column
        label="可提现金额"
        align="center"
      
      >
        -
      </el-table-column>
      <el-table-column
        label="余额"
        align="center"
        prop="balance"
      />
      <el-table-column
        label="总计奖金"
        align="center"
        prop="totalBonus"
      />
      <el-table-column
        label="奖金"
        align="center"
        prop="bonus"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createdAt"
      >
      </el-table-column>
      <el-table-column
        label="更新时间"
        align="center"
        prop="modifiedAt"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row.id)"
            v-hasPermi="['system:clientUser:detail']"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    
    <userDetail ref="userDetailRef"></userDetail>

  </div>
</template>
  
  <script>
import { listClientUser, getClientUser } from "@/api/system/clientUser";
import userDetail from '@/views/system/clientUser/userDetail.vue'

export default {
  
  name: "ClientUser",
  components: {userDetail},
  data() {
    return {
      clientUserDetailVis: false,
      direction: "ltr",
      userDetail: {},
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户端用户表格数据
      clientUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: null,
        imeiCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客户端用户列表 */
    getList() {
      this.loading = true;
      listClientUser(this.queryParams).then((response) => {
        this.clientUserList = response.data.data;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    handleDetail(id) {
      this.$refs.userDetailRef.clientUserDetailVis = true;
      getClientUser(id).then((res) => {
        this.$refs.userDetailRef.userDetail = res.data;
      });
      this.$refs.userDetailRef.queryParams.userId = id
      this.$refs.userDetailRef.getList() 
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        phone: null,
        imeiCode: null,
        password: null,
        passwordEncry: null,
        withdrawAmount: null,
        unWithdrawAmount: null,
        createTime: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },
};
</script>
  